import java.util.Scanner;
import java.util.Stack;

public class Test7 {
    public static int solve (char[][] grid) {
        char[][] arr=new char[grid.length-1][grid[0].length];
        char[][] brr=new char[grid.length][grid[0].length-1];
        int m=0;
        for(int i=1;i<grid.length;i++){

            int n=0;
            for(int j=0;j<grid[i].length;j++){
                arr[m][n++]=grid[i][j];
            }
            m++;
        }
        m=0;
        for(int i=0;i<grid.length;i++){

            int n=0;
            for(int j=1;j<grid[i].length;j++){
                brr[m][n++]=grid[i][j];
            }
            m++;
        }
        // write code here
        if( grid[0][0] == 1 &&(arr[0][0] == 1 || brr[0][0] == 1)){
            return Math.max(solve(arr),solve(brr))+1;
        }else{
            return Math.max(solve(arr),solve(brr));
        }
    }
    public static void main(String[] args) {
       char[][] grid={{1,0,0,0,0},{0,1,0,1,1},{0,0,0,1,1},{0,0,0,0,0},{0,0,1,1,1}};
       int n=solve(grid);
        System.out.println(n);
    }









    public static void main01(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int i = 0;
            int prev1 = -1;
            int prev2 = -1;
            int ret = -1;
            int k=-1;int l=-1;
            int a=prev1;
            int b=prev2;
            for (; i <= str.length() - 2; i++) {

                if (i==0 && str.charAt(0) >= '0' && str.charAt(0) <= '9') {
                    prev1 = 0;
                }
                if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z' ) {
                    if (str.charAt(i + 1) >= '0' && str.charAt(i + 1) <= '9') {
                        prev1 = i +1;
                    }
                }
                if (str.charAt(i ) >= '0' && str.charAt(i ) <= '9'){
                    if (str.charAt(i + 1) >= 'a' && str.charAt(i + 1) <= 'z' ) {
                        prev2 = i;
                    }
                    if(i==str.length()-2){
                        prev2=i+1;
                    }
                }
                if (prev1 != a && prev2 != b ) {
                    if (ret < prev2 - prev1 + 1) {
                        k = prev1;
                        l = prev2;
                        a = prev1;
                        b=prev2;
                    }
                    ret = ret > prev2 - prev1 + 1 ? ret : prev2 - prev1 + 1 ;
                }
            }

            for(int j=k;j<=l;j++){
                System.out.print(str.charAt(j));
            }

        }
    }
}
